<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div {
    font-size: 30px;
    width: 120px;
    height: 50px;
    background-color: pink;
    text-align: center;
    line-height: 50px;
    
}
</style>
</head>
<body>
<div id="box"></div>
<a href="javascript:" id="btn">看不清</a>
<script>
var box = document.getElementById("box");
var btn = document.getElementById("btn");

showVerificationCode();
btn.onclick = function (){
    showVerificationCode()
}

/**
 * 展示验证码
 */
function showVerificationCode(){
    var a = createVerificationCode();
    var res = a.join(" ");
    box.innerHTML = res;
}

/**
 生成验证码
 */
function createVerificationCode(){
    var source = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "我", "好"]
    var a = [];
    for (var i = 0; i < 4; i++){
        var index = randomInt(0, source.length - 1)
        a.push((source[index] + "").toUpperCase())
    }
    return a;
}

/**
 作者:李振超      2017年7月26日 09:48
 返回随机的 [from, to] 之间的整数(包括from，也包括to)
 */
function randomInt(from, to){
    return parseInt(Math.random() * (to - from + 1) + from);
}

</script>
</body>
</html>
<!--
    作者：李振超  2017年7月26日08:41
    3. 生成验证码：
-->